package li.brauch.semesterarbeit.radio.impl;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import li.brauch.semesterarbeit.radio.AbstractRadio;
import li.brauch.semesterarbeit.radio.model.StationTuneModel;
import li.brauch.semesterarbeit.radio.model.StationTuneResultModel;
import li.brauch.semesterarbeit.radio.model.Track;

public class Mock2RadioImpl extends AbstractRadio {
	
	private List<Track> playList = new ArrayList<Track>();
	
	private int index = 0;
	
	private boolean ambiguous = true;
	
	public Mock2RadioImpl() {
		
		Track track = new Track();
		track.setId(1001);
		track.setAlbum("Human Zoo");
		track.setTitle("Human Zoo");
		track.setArtist("Gotthard");
		track.setDuration(315000);
		URL resource = getURL("http://www.brauch.li/Human%20Zoo.mp3");
		track.setLocation(resource);
		resource = getURL("http://www.brauch.li/cover_gotthard.png");
		track.setCover(resource);
		playList.add(track);
		
		track = new Track();
		track.setId(1001);
		track.setAlbum("Greatest Hits");
		track.setTitle("Welcome to the jungle");
		track.setArtist("Guns N' Roses");
		track.setDuration(310000);
		resource = getURL("http://www.brauch.li/Welcome%20To%20The%20Jungle.mp3");
		track.setLocation(resource);
		resource = getURL("http://www.brauch.li/cover_gunnroses.png");
		track.setCover(resource);
		playList.add(track);
	}
	
	public void login() {		
		
	}
		
	public String[] getStationTypes() {
		return new String[] {"Artist"};
	}
		
	public StationTuneResultModel tuneStation(StationTuneModel model) {
		
		StationTuneResultModel result = new StationTuneResultModel();
		if (ambiguous) {
			result.setResults( new String[] { model.getName() + " 1", model.getName() + " 2"});
			ambiguous = false;
		} else {
			result.setResults( new String[] { model.getName() + " 1"});
		}
		
		return result;
	}
	
	public Track getNextTrack() {
		
		index++;
		
		if (index == playList.size())
			index = 0;
		
		Track track = playList.get(index);
		
		
		
		return track;
	}
	
	public void banTrack() {
		Track track = playList.get(index);
		System.out.println("Track " + track.getTitle() + " from artist " + track.getArtist() + " baned");
	}
	
	public void loveTrack() {
		Track track = playList.get(index);
		System.out.println("Track " + track.getTitle() + " from artist " + track.getArtist() + " loved");
	}

	private URL getURL(String url) {
		URL result = null;
		try {
			result = new URL(url);
		} catch (MalformedURLException e) {}
		
		return result;
	}
}